package com.ttbj.yitongpay.util;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
/**
 * 专门读取 ytpay.properties 文件的工具类
 * @Date 2018年8月29日 下午3:46:59
 */
public class PropertiesUtil {
	private static volatile PropertiesUtil configuration = null;
	private Properties pros = null;
	
	private PropertiesUtil(){
		readConfig();
	}
	
	public static PropertiesUtil getInstance(){
		if (null == configuration) {
			synchronized(PropertiesUtil.class) {
				if(configuration == null){
					configuration = new PropertiesUtil();
				}
			}
		}
		return configuration;
	}
	
	public String getValue(String key){
		return pros.getProperty(key);
	}
	
	private void readConfig() {
		pros = new Properties();		
		InputStream in = null;
		try {
			in = Thread.currentThread().getContextClassLoader().getResourceAsStream("yitong/ytpay.properties");
			pros.load(in);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}catch (IOException e) {
			e.printStackTrace();
		}finally{
			try {
				in.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
}
